package com.lecture.javamode.proxy.staticproxy;


//userController代理类
public class UserControllerProxy implements IUserController {

    private MetricsCollector metricsCollector;
    private UserController userController;

    public UserControllerProxy( UserController userController) {
        this.metricsCollector = new MetricsCollector();
        this.userController = userController;
    }

    @Override
    public void login(String userName, String pwd) {
        long startTimestamp = System.currentTimeMillis();

        //委托
        userController.login(userName,pwd);


        long endTimestamp = System.currentTimeMillis();
        long responseTime = endTimestamp - startTimestamp;
        RequestInfo requestInfo = new RequestInfo("login",responseTime,startTimestamp);
        metricsCollector.recordRequest(requestInfo);
    }
}
